home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 651-660 / 658 / view / source / print.c < prev    next >
C/C++ Source or Header  |  1995-03-15  |  6KB  |  177 lines

  1. /*-- AutoRev header do NOT edit!
  2. *
  3. *   Program         :   Print.c
  4. *   Copyright       :   Copyright © 1991-92 Jaba Development
  5. *   Author          :   Jan van den Baard
  6. *   Creation Date   :   05-Apr-92
  7. *   Current version :   2.0
  8. *   Translator      :   Dice v2.06.40
  9. *
  10. *   REVISION HISTORY
  11. *
  12. *   Date          Version         Comment
  13. *   ---------     -------         ------------------------------------------
  14. *   05-Apr-92     2.0             Printer routines. (rewrite)
  15. *
  16. *-- REV_END --*/
  17.  
  18. #include "View.h"
  19.  
  20. Prototype void PrintFile( void );
  21. Prototype long CheckPrinter( void );
  22. Prototype __geta4 void PrintProc( void );
  23.  
  24. extern struct Screen            *vwScreen;
  25. extern struct Window            *vwWindow;
  26. extern struct RastPort          *vwRPort;
  27. extern struct AsciiText         *vwText;
  28. extern struct Line              *vwFirst, *vwLast;
  29. extern struct TextFont          *vwFont;
  30. extern struct TextBlock          vwBlocks[];
  31. extern UWORD                     vwPMark, vwPMode;
  32. extern UBYTE                     vwPrinting;
  33. extern ULONG                     vwClass;
  34. #ifdef __DETACH
  35. extern ULONG                    *vwArgs;
  36. #else
  37. extern ULONG                     vwArgs[];
  38. #endif
  39.  
  40. extern __far struct Custom       custom;
  41.  
  42. void PrintFile( void )
  43. {
  44.     if ( ! vwText )     return;
  45.  
  46.     if ( vwPMode == PRT_BLOCK ) {
  47.         if ( ! CheckBlock( vwPMark ))
  48.             return;
  49.     }
  50.  
  51.     if ( ! CreateNewProcTags( NP_Entry,     PrintProc,
  52.                               NP_StackSize, 4096L,
  53.                               NP_Name,      "ViewPrinting",
  54.                               NP_Cli,       TRUE,
  55.                               TAG_DONE ))
  56.         Error( "Can't start the printing process." );
  57.     else {
  58.         while( ! FindTask( "ViewPrinting" ));
  59.         vwPrinting = TRUE;
  60.     }
  61. }
  62.  
  63. long CheckPrinter( void )
  64. {
  65.     struct Data {
  66.         UBYTE   LSB, MSB;
  67.     } data;
  68.  
  69.     struct MsgPort  *port;
  70.     struct IOStdReq *pio;
  71.     UBYTE           *ptr;
  72.     long             ret = TRUE;
  73.     UBYTE            ch = FALSE;
  74.  
  75.     if ( port = CreateMsgPort()) {
  76.         if ( pio = CreateStdIO( port )) {
  77.             if ( ! OpenDevice( "printer.device", NULL, ( struct IORequest * )pio, NULL )) {
  78.  
  79.                 retry:
  80.  
  81.                 pio->io_Data    =   (APTR)&data;
  82.                 pio->io_Command =   PRD_QUERY;
  83.  
  84.                 DoIO(( struct IORequest * )pio );
  85.  
  86.                 if (( data.LSB & 1 ) || ( data.LSB & 2 )) {
  87.  
  88.                     if( vwArgs[ 11 ] )  {
  89.                         vwArgs[ 11 ] = NULL;
  90.                         ch = TRUE;
  91.                         ON_SPRITE;
  92.                     }
  93.  
  94.                     if ( rtEZRequestTags( "Your printer isn't online or\nyou must insert paper.",
  95.                                       "Retry|Cancel",
  96.                                       NULL,
  97.                                       NULL,
  98.                                       RT_Window,      vwWindow,
  99.                                       RT_ReqPos,      REQPOS_CENTERSCR,
  100.                                       RTEZ_Flags,     EZREQF_CENTERTEXT,
  101.                                       RTEZ_ReqTitle,  CX_NAME ": Printer trouble...",
  102.                                       TAG_DONE ))
  103.                         goto retry;
  104.                     else
  105.                         ret = FALSE;
  106.                 }
  107.                 CloseDevice(( struct IORequest * )pio );
  108.             }
  109.             DeleteIORequest(( struct IORequest * )pio );
  110.         }
  111.         DeleteMsgPort( port );
  112.     }
  113.  
  114.     if ( ptr = AllocMem( 102857600, MEMF_ANY ))
  115.         FreeMem( ptr, 102857600 );
  116.  
  117.     if ( ch ) {
  118.         vwArgs[ 11 ] = ~0;
  119.         OFF_SPRITE;
  120.     }
  121.  
  122.     return( ret );
  123. }
  124.  
  125. __geta4 void PrintProc( void )
  126. {
  127.     struct BuffIO           *pfile = NULL;
  128.     struct Window           *pwin  = NULL;
  129.     struct Line             *l, *t;
  130.     UBYTE                   *title = "Printing...";
  131.  
  132.     if ( ! CheckPrinter())
  133.         goto CleanExit;
  134.  
  135.     if ( pfile = BOpen( "PRT:", MODE_NEWFILE )) {
  136.         if ( pwin = OpenWindowTags( NULL, WA_Width,         TextLength( vwRPort, title, 11 ) + 20,
  137.                                           WA_Height,        vwScreen->WBorTop + vwFont->tf_YSize + 1,
  138.                                           WA_Title,         title,
  139.                                           WA_IDCMP,         IDCMP_CLOSEWINDOW,
  140.                                           WA_Flags,         WFLG_SMART_REFRESH | WFLG_CLOSEGADGET | WFLG_DRAGBAR  | WFLG_RMBTRAP,
  141.                                           WA_CustomScreen,  vwScreen,
  142.                                           TAG_DONE )) {
  143.             switch( vwPMode ) {
  144.                 case    PRT_PAGE:
  145.                     l = vwFirst;
  146.                     t = vwLast;
  147.                     break;
  148.  
  149.                 case    PRT_FILE:
  150.                     l = vwText->First;
  151.                     t = vwText->Last->Next;
  152.                     break;
  153.  
  154.                 case    PRT_BLOCK:
  155.                     l = vwBlocks[ vwPMark ].TopLine;
  156.                     t = vwBlocks[ vwPMark ].BottomLine;
  157.                     break;
  158.             }
  159.  
  160.             for ( ; l != t; l = l->Next ) {
  161.                 if ( ReadMsgPort( pwin->UserPort )) {
  162.                     if ( vwClass == IDCMP_CLOSEWINDOW )
  163.                         goto CleanExit;
  164.                 }
  165.                 BPutS( pfile, l );
  166.             }
  167.         } else
  168.             Error( "Could not open the printer window." );
  169.     } else
  170.         Error( "Printer trouble." );
  171.  
  172. CleanExit:
  173.     if ( pwin )     CloseWindow( pwin );
  174.     if ( pfile )    BClose( pfile );
  175.     vwPrinting = FALSE;
  176. }
  177.